<?php
/*
 * @Author: CHINAKAIYUAN<sunkaiyuan@namenode.cn>
 * @Date: 2022-02-02 19:42:06
 * @LastEditTime: 2023-07-24 13:04:14
 * @LastEditors: 孙开源 && sunkaiyuan@namenode.cn
 * @Description: 
 */

namespace App\Repositories;

use App\Models\ProColor;

use Illuminate\Support\Facades\Storage;
use Intervention\Image\Facades\Image;

class ProColorRepository extends Repositories
    {
    public $relation_models = ["material", "creator", 'company', 'attachments', 'ColorShade'];
    public function boot(ProColor $model)
        {
        $this->model = $model;
        }
    //模糊搜索
    public function fuzzySearch($value)
        {
        $value = trim($value);
        $this->where(function ($query) use ($value)
            {
            $query->orWhere("name", "like", "%{$value}%");
            $query->orWhere("code", "like", "%{$value}%");
            $query->orWhere("code_my", "like", "%{$value}%");
            });
        }
    //同步颜色的色卡色号
    public function sync_codemy($color_id)
        {
        $color_data          = $this->whereId($color_id)->first();
        $color_data->code_my = $color_data->color_revision()->where("code_my", "<>", "")->where('material_id', '<>', 2342)->implode("code_my", "/");
        $color_data->save();
        }
    }